﻿using System.Web;

namespace PrivateTracker.Service.Core;
/// <summary>
/// 枚举扩展
/// </summary>
public static class ByteUtil
{
    /// <summary>
    /// bytes转换为string
    /// </summary>
    /// <param name="bytes"></param>
    /// <returns></returns>
    public static string GetHexString(this Byte[] bytes)
    {
        if (!bytes.Any()) return null;
        return BitConverter.ToString(bytes).Replace("-", string.Empty);
    }
    /// <summary>
    /// 转义转换为string
    /// </summary>
    /// <param name="infoHash"></param>
    /// <returns></returns>
    public static string GetHexString(this string infoHash)
    {
        if (string.IsNullOrWhiteSpace(infoHash)) return null;
        byte[] vs = HttpUtility.UrlDecodeToBytes(infoHash);
        return BitConverter.ToString(vs).Replace("-", string.Empty);
    }
}